var Store = {
    counter : {}
};
Store.locStorage = {};

/**
 * obj must contain storeName, storeId
 */
Store.locStorage.add = function(obj) {
    var storeName = obj.storeName;
    var storeId = obj.storeId;
    var _ls = window.localStorage;

    if (!storeName || !storeId) {
        return "error";
    }

    if (_ls.getItem(storeName)) {
        _ls.getItem(storeName)[storeId] = obj;
    } else {
        obj.version = 1;
        _ls.setItem(storeName, {});
        _ls.getItem(storeName)[storeId] = obj;
    }

    return "success";
};

Store.locStorage.del = function(obj) {
    var storeName = obj.storeName;
    var storeId = obj.storeId;
    var _ls = window.localStorage;
    
    if (!storeName || !storeId) {
        return "error";
    }

    if (_ls.getItem(storeName)) {
        var _obj = _ls.getItem(storeName)[storeId];

        if (_obj) {
            _ls.getItem(storeName).removeChild(_obj);
        }

        if (_ls.getItem(storeName).length == 0) {
            _ls.removeItem(storeName);
        }
    }
};

Store.locStorage.update = function() {
    //TODO
};

Store.getCounter = function(args) {
    if(Store.counter.length == 0 && window.localStorage.counter){
        Store.counter = window.localStorage.counter;
    }
    
    if(!Store.counter[args]){
        Store.counter[args] = 0;
    }
    
    Store.counter[args]++;
    window.localStorage.counter = Store.counter;
    return Store.counter[args];
};

Store.add = function(obj) {
    var flag = false;
    url = U.basepath + "/addTimingTasks.do";
    $.post(url, obj, function(data){
        E.saveCallback(data);
    });

    return flag;
};